<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ taglib prefix="his_fns" uri="/WEB-INF/tlds/his_fns.tld" %>
<script type="text/javascript">

</script>
<div class="content-wrap">
    <div class="wrapper" style="bottom: 50px;">
        <ul class="nav nav-tabs">
            <li class="active">
                <a href="#">出库记录详情</a>
            </li>
        </ul>
        <section class="panel panel-default">
            <div class="panel-body">
                <div class="table-responsive no-border">
                    <form:form id="searchForm" modelAttribute="drugImportMaster"
                    onsubmit="return loadDivForm('mainCenterDiv','searchFormDict','${ctx}/drug/drugStock/batchImport');"
                    method="post" class="form-inline">
                    <div class="form-group">
                    <label class=" control-label">入库类别：</label>
                    <form:select path="importClass" id="importClass" htmlEscape="false" class="form-control" maxlength="1" data-parsley-required="true">
                    <form:options items="${his_fns:getBatchImportClassDictList()}" itemLabel="label" itemValue="value" htmlEscape="false" />
                    </form:select>
                    </div>
                    <a href="#" onclick="drugIn('${drugExportDetail.masterId}')" class="btn btn-primary" style="margin-bottom: 10px">入库</a>
                    </form:form>
                        <table id="itemTable" class="table table-bordered mg-t datatable">
                        <thead>
                        <tr>
                            <th>药品名称</th>
                            <th>包装规格</th>
                            <th>单位</th>
                            <th>厂家</th>
                            <th>批号</th>
                            <th>有效期</th>
                            <th>价格</th>
                            <th>数量</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${drugExportDetaiList}" var="drugExportList">
                            <tr>
                                <td> ${drugExportList.drugCode}</td>
                                <td> ${drugExportList.packageSpec}</td>
                                <td> ${fns:getDictLabels(drugExportList.packageUnits, 'SPEC_UNIT', '')}</td>
                                <td> ${drugExportList.remarks}</td>
                                <td> ${drugExportList.batchNo}</td>
                                <td><fmt:formatDate value="${drugExportList.expireDate}" pattern="yyyy-MM-dd"/></td>
                                <td> ${drugExportList.purchasePrice}</td>
                                <td> ${drugExportList.quantity}</td>
                            </tr>
                        </c:forEach>
                    </table>
                </div>
            </div>
        </section>
    </div>
</div>
<script>
    function drugIn(masterId){
        var importClass = $("#importClass").val();
        //将出库主表Id放在remarks上放到后台
        if(importClass !="" && importClass !=null){
            $.ajax({
                type: "POST",
                url: '${ctx}/drug/drugStock/saveBatchImport?importClass='+importClass+'&remarks='+masterId,
                'contentType': 'application/json',
                dataType: "json",
                success: function (data) {
                    console.log(data);
                    if (data.code = "success") {
                        toastr.success('入库成功');
                        $('#btnSubmit').click();
                        layer.open({
                            title: "需要打印单据吗?",
                            type: 1,
                            area: ['300px', '150px'],
                            fixed: false, //不固定
                            skin: 'layui-layer-rim',
                            maxmin: true,
                            content:"",
                            btn: ['确定', '取消'],
                            yes: function (index, layero) {
                                printPdf('${ctx}/drug/drugDetails/drugImportDetailsPrint?masterId='+data.data);
                            }, no: function (index) {
                                layer.close(index);
                            }
                        });
                    } else {
                        toastr.success('入库失败');
                    }
                },
                error: function (data) {
                    toastr.error('网络连接错误,请检查网络');
                }
            });
        }else{
            toastr.error('请选择入库方式');
        }
    }
</script>

